package com.atguigu.gulimall.search.controller;


import com.atguigu.common.to.EsSkuInfo;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ElasticSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("elastic/save")
@Slf4j
public class ElasticSaveController {
    @Autowired
    private ElasticSaveService elasticSaveService;

    @PostMapping("/product")
    public R productStatuUp(@RequestBody List<EsSkuInfo> esSkuInfo) {
        Boolean aBoolean = false;
        try {
            aBoolean = elasticSaveService.productStatuUp(esSkuInfo);
        } catch (IOException e) {
            log.error("商品上架异常");
        }
        if (aBoolean) {
            log.error("商品上架异常");
            return R.error("商品上架异常").put("boolean", false);

        } else {
            return R.ok().put("boolean", true);
        }
    }
}
